package com.example.server.Contr;

import com.example.server.Service.UserService;
import com.example.server.entity.User;
import com.example.server.mapper.Usermapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.NoSuchAlgorithmException;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/user")
public class UserContr {
    @Autowired
    private UserService userser;
    @RequestMapping("/login")
    public User login(@RequestParam("username") String username, @RequestParam("password") String password) throws NoSuchAlgorithmException {
        return userser.se(username,password);
    }
    @RequestMapping("/adminlogin")
    public boolean adminlogin(@RequestParam("key") String key){
        String one = "1";
        if(key.equals(one))
            return true;
        else
            return false;
    }
    @RequestMapping("/register")
    public boolean regis(@RequestBody User user) throws NoSuchAlgorithmException {
        System.out.println("正在注册用户"+user);
        return userser.re(user);
    }
    @RequestMapping("/self")
    public User self(@RequestParam("uid") String uid){
        return userser.self(uid);
    }
    @RequestMapping("/complete")//个人信息完善。
    public boolean complete(@RequestBody User ua){
        System.out.println(ua);
        return userser.update(ua);
    }
    @RequestMapping("/adminselectuser")
    public int select(){
        return userser.select();
    }
    @RequestMapping("/getalluser")
    public List<User> get(){
        return userser.get();
    }
    @RequestMapping("/deleteuser")
    public int deleteuser(@RequestParam("uid") int id){
        return userser.deleteuser(id);
    }
}
